/****************************************************************************************************************************
* The Hand behaviour class controls the location of the hand geometry, provides the flying around the world ability			*
* and allows us to drag objects at random around the world.																	*		
*																															*
* 1/2005 - Ross Smith																										*
*																															*
* re-written to remove the floating point errors that occured due to the scene graph design. Previously the hand			*
* and the users view flew around the world by adding an offset to the origin of the polhemus transmitter.  The new			*
* structure moves the world around the users hand and head (view) so both the hand and head are always relative to the		*
* polhemus transmitter.																										*
*																															*	
****************************************************************************************************************************/

import javax.media.j3d.*;
import java.util.*;

public class HandBehaviorSecondary extends HandBehaviorGeneric {

    public HandBehaviorSecondary(Hand hand, Sensor trackerSensor, ButtonDevice mouse, TransformGroup viewPlatform, 
		BranchGroup scene, TransformGroup worldBranch)
    {
    	super(hand, trackerSensor, mouse, viewPlatform, worldBranch);
    }

    
	public void processStimulus (Enumeration criteria) {

		/*Set the location of the hand*/
       	setHandPosition();
      	
       	if(buttonDevice == null){
       		wakeupOn (wakeupConditions);	
       		return;
       	}
       	
       	/*Set the states of the buttons*/
        button[0] = buttonDevice.getButton(6);
       	button[1] = buttonDevice.getButton(7);
       	button[2] = buttonDevice.getButton(8);
       	button[3] = buttonDevice.getButton(9);
       	button[4] = buttonDevice.getButton(10);
       	
       	/*Set the look of the hand to represent its actual state*/	
       	hand.setTopRightButtonState(button[0]);
		hand.setRightButtonState(button[2]);
		hand.setTopLeftButtonState(button[4]);
		hand.setLeftButtonState(button[3]);
	    hand.setTopMiddleButtonState(button[1]);
	   
        /* Check if we need to drop an object */
        if (!button[1])
        	testForDrop();
        
        /*Check if we are attempting to grab an object */
    	if (button[1])
    		testForGrab();
    
    	wakeupOn (wakeupConditions);
	}
}
